package Thread;
/**
 * wait - notify结合的使用
 */

import java.util.Scanner;

public class Demo25 {
    private static Object locker = new Object();//锁对象

    public static void main(String[] args) {
        Thread t1 = new Thread(() ->{
            synchronized (locker) {
                System.out.println("t1 wait之前");

                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

                System.out.println("wait 之后");
            }
        });

        Thread t2 = new Thread(() -> {
            System.out.println("t2 notify 之前");
            Scanner scanner = new Scanner(System.in);
            scanner.next();//此处用户输入啥都行,主要是通过这个next构造阻塞

            synchronized (locker){
                locker.notify();
            }

            System.out.println("t1 notify 之后");
        });

        t1.start();
        t2.start();
    }
}
